package pile.pay.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import pile.pay.config.wxConfig.WxPayEntity;
import pile.pay.config.wxConfig.WxRefundEntity;
import pile.pay.entity.ResponseResult;
import pile.pay.service.IWxPayService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.Map;

/**
 * @Description:
 **/

@RestController
@RequestMapping("/wxpay")
@Api(tags = {"微信支付接口详情"})
public class WxPayController {

    @Autowired
    private IWxPayService wxPayService;

    /**
     * 统一下单-统一接口
     */
    @PostMapping("/transactions")
    @ApiOperation(value = "统一下单", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult transactions(@Validated @RequestBody WxPayEntity wxPayEntity) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
        return wxPayService.transactions(wxPayEntity);
    }

    //支付回调
    @PostMapping("/payNotify")
    @ApiOperation(value = "支付回调", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public Map<String, String> payNotify(HttpServletRequest request, HttpServletResponse response) {
        return wxPayService.payNotify(request,response);
    }

    /**
     * 申请退款
     */
    @PostMapping("/refunds")
    @ApiOperation(value = "申请退款", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult refunds()  {
        return wxPayService.refunds();
    }


    /**
     * 退款回调
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/refundNotify")
    @ApiOperation(value = "退款回调", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public Map<String, String> refundNotify(HttpServletRequest request, HttpServletResponse response) {
        return wxPayService.refundNotify(request,response);
    }



}